from eval_lib.common.exceptions import BadRequestException
from eval_lib.model.base import BaseStruct


class ResultPostLog(BaseStruct):

    KEYS = ["uuid", "type", "data"]

    def is_valid(self):
        # TODO
        if not self.uuid or self.type is None:
            raise BadRequestException("bad request")
        return True


class ResultGetLog(BaseStruct):

    KEYS = ["uuid", "type", "line_index", "line_size"]

    def init(self, **kwargs):
        super().init(**kwargs)
        self.type = int(self.type) if self.type is not None else self.type
        if not self.line_index:
            self.line_index = 1
        if not self.line_size:
            self.line_size = 0
        self.line_index = int(self.line_index)
        self.line_size = int(self.line_size)

    def is_valid(self):
        # TODO
        if not self.uuid or self.type is None:
            raise BadRequestException("bad request")
        return True


class ResultLogResponse(BaseStruct):

    KEYS = ["uuid", "logs", "line_index", "line_size", "line_count"]


class ResultGetFile(BaseStruct):

    KEYS = ["uuid", "type"]

    def init(self, **kwargs):
        super().init(**kwargs)
        self.type = int(self.type) if self.type is not None else self.type

    def is_valid(self):
        # TODO
        if not self.uuid or self.type is None:
            raise BadRequestException("bad request")
        return True


class ResultFileResponse(BaseStruct):

    KEYS = ["uuid", "files"]